# -*- coding:utf-8 -*-
# author:qiong   time:2021/9/19
import allure
from selenium.webdriver.common.by import By
from mkzAPP_test.base.baseApp import basePageElement, baseHandle
from mkzAPP_test.utils_app import swipe_find


class classificationElement(basePageElement):
    def __init__(self):
        super().__init__()
        # 展开按钮
        self.expand_btn = By.ID,"com.xmtj.mkz:id/expand_radiobutton"
        # 霸总选项按钮
        self.potentMan_btn = By.XPATH,"//*[@text='霸总']"
        # 完结选项按钮
        self.finish_btn = By.XPATH,"//*[@text='完结']"
        # VIP选项按钮
        self.VIP_btn = By.XPATH,"//*[@text='VIP']"
        # 滑屏起始元素
        self.scrollStart_element = By.ID,"com.xmtj.mkz:id/rg_hot_new"
        # 滑屏希望找到的元素
        self.target_element = By.XPATH, "//*[@text='明星是血族']"

    def find_expand_btn(self):
        return self.wait_getelement(self.expand_btn)

    def find_potentMan_btn(self):
        return self.wait_getelement(self.potentMan_btn)

    def find_finish_btn(self):
        return self.wait_getelement(self.finish_btn)

    def find_VIP_btn(self):
        return self.wait_getelement(self.VIP_btn)

    def find_scrollStart_element(self):
        return self.wait_getelement(self.scrollStart_element)




class classificationHandle(baseHandle):
    def __init__(self):
        self.classification_element = classificationElement()

    # 点展开按钮
    def click_expand_btn(self):
        self.classification_element.find_expand_btn().click()

    # 点击霸总选项
    def click_potentMan_btn(self):
        self.classification_element.find_potentMan_btn().click()

    # 选择完结
    def click_finish_btn(self):
        self.classification_element.find_finish_btn().click()

    # 点击选择VIP
    def click_VIP_btn(self):
        self.classification_element.find_VIP_btn().click()

    # 调用滑动查找方法查到漫画
    @allure.step(title="查找到指定漫画")
    def scroll_swipe_find(self):
        swipe_find(self.classification_element.driver,self.classification_element.find_scrollStart_element(),self.classification_element.target_element)
        # 截图至allure
        allure.attach(self.classification_element.driver.get_screenshot_as_png(), "截图", allure.attachment_type.PNG)

class classificationProxy:
    def __init__(self):
        self.classification_Handle = classificationHandle()

    # 查找漫画
    def find_cartoon(self):
        self.classification_Handle.click_expand_btn()
        self.classification_Handle.click_potentMan_btn()
        self.classification_Handle.click_finish_btn()
        self.classification_Handle.click_VIP_btn()
        self.classification_Handle.scroll_swipe_find()

